package wsi.subgraph.tree;

import org.rygh.core.face.IEquable;
import org.rygh.core.face.IHasName;
import org.rygh.core.face.IHasValue;
import org.rygh.semantic.model.rdf.Entity;
import org.rygh.semantic.model.rdf.Predicate;

public class EntityObject implements IHasName, IHasValue<Entity>, IEquable {

	private final Entity value;
	private Predicate predicate;

	public EntityObject(Entity value, Predicate predicate) {
		this.value = value;
		this.predicate = predicate != null ? new Predicate(predicate) : null;
	}

	public EntityObject(EntityObject value) {
		this(value.getValue(), value.getPredicate());
	}

	@Override
	public boolean equalsTo(Object o) {
		return o == null ? false : getValue().equals(
				((EntityObject) o).getValue());
	}

	@Override
	public String getName() {
		return value.getValue();
	}

	public Predicate getPredicate() {
		return predicate;
	}

	@Override
	public Entity getValue() {
		return value;
	}

	public boolean isInverse() {
		return predicate.isInverse();
	}

	public void setPredicate(Predicate predicate) {
		this.predicate = predicate;
	}

	@Override
	public String toString() {
		return "EntityObject [predicate=" + predicate + ", entity=" + value
				+ "]";
	}

}
